Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

011.Container With Most Water (java) #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
yanglbme merged 1 commit into doocs:master from bluesword12350:master
Oct 30, 2018
Merged

011.Container With Most Water (java) #72

yanglbme merged 1 commit into doocs:master from bluesword12350:master
Oct 30, 2018

Conversation

@bluesword12350
Copy link
Member

@bluesword12350 bluesword12350 commented Oct 30, 2018

None.

@@ -0,0 +1,18 @@
class Solution {
public int maxArea(int[] height) {
int start = 0, end = height.length - 1, maxArea = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

虽然题目没有说明是否有非空的情况,但如果从程序健壮性/实际应用的角度来看,加以下一小段代码是有必要的噢~

if (height == null || height.length < 2) {
 return 0;
}

否则当传入 null 时,程序直接抛 NPE

Copy link
Member Author

@bluesword12350 bluesword12350 Oct 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
题目中恰好有提到 数组长度至少为2。

Copy link
Member Author

@bluesword12350 bluesword12350 Oct 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yanglbme yanglbme merged commit 96e4f03 into doocs:master Oct 30, 2018
Copy link
Member

@bluesword12350
好的哈,是我看漏了,程序代码写得很棒~

Copy link
Member Author

@yanglbme 多谢,其实考虑单个函数的健壮性,还是应该加上,不过现在开发多了分布式系统,一些参数在多个服务间流转,如果每个去检测的话,会出现参数重复检测的问题,我一般都是在入口进行统一参数验证,之后都默认参数合格的。
做这些练习题也就习惯,只要不需要验证的我都没有专门进行验证。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@yanglbme yanglbme yanglbme left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /